// import {accountLoginRequest} from "@/service/login/login.js"
import LocalCache from "@/utils/cache"
// import axios from "axios"
import router from "@/router";

import isdialogVisible from "@/utils/isdialogVisible"

import {accountLoginRequest,Emaillog} from "@/service/login/login"

const loginModule = {
    namespaced:true,
    state() {
        return {
          token: '',
          userInofo: {},
        }
      },
      mutations: {
        //修改token
        changeToken(state, token) {
          state.token = token
        },
        changeUseInfoResult(state, userInofo) {
          state.userInofo = userInofo
        },
      
      },
      actions: {
        async accountLoginAction({ commit }, payload) {
          //1登录逻辑
          const loginResult = await accountLoginRequest(payload)
          //保存token和id
          console.log(loginResult,'loginResult');
          const { id, token,url,phone,industry,name } = loginResult
          commit('changeToken', token)
          LocalCache.setCache('token', token)
          LocalCache.setCache('id', id)
          LocalCache.setCache("url",url)
          LocalCache.setCache("industry",phone )
          LocalCache.setCache("phone",industry)
          LocalCache.setCache("name",name)
          if (token) {
            router.push("/main/0")
            isdialogVisible.value = false
          }
          commit("changeUseInfoResult",loginResult)
        },
        async phoneLoginAction({commit},payload){
          console.log(commit,payload)
          const res = await Emaillog(payload)
          console.log(res);
        }
        //定义一个方法解决用户刷新浏览器导致vuex里保存的数据丢失
        // LoadLocalLogin({ commit }) {
        //   const token = LocalCache.getCache('token')
        //   if (token) {
        //     commit('changeToken', token)
        //   }
        //   const userInofo = LocalCache.getCache('userInofo')
        //   if (userInofo) {
        //     commit('changeUseInfoResult', userInofo)
        //   }
        //   const UserMenus = LocalCache.getCache('UserMenus')
        //   if (UserMenus) {
        //     commit('changeMenusResult', UserMenus)
        //   }
        // }
    
     
      },
      modules: {}
    }
    export default loginModule